package com.glory.dgcpcpda.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.dgcpcpda.R;
import com.glory.dgcpcpda.entity.ChangeShiftEntity;

import java.util.List;

/**
 * FileName: ChangeShiftsAdapter
 * Author: XJH
 * Date: 2020/7/1 19:31
 * Description:
 * History:
 */
public class ChangeShifts2Adapter extends BaseQuickAdapter<ChangeShiftEntity.ChangeShift, BaseViewHolder> {

    private String mShiftNo = "";
    public ChangeShifts2Adapter(@Nullable List<ChangeShiftEntity.ChangeShift> data) {
        super(R.layout.item_change_shift_adapter2,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChangeShiftEntity.ChangeShift item) {
        helper.setText(R.id.tvEqpID,item.getRESERVED03());
        helper.setText(R.id.tvLot,item.getItemId());
        helper.setText(R.id.tvWorkNo,item.getCHANGESHIFTID());
        helper.setText(R.id.tvShiftNo,mShiftNo);
        helper.setText(R.id.tvShiftNum,item.getRESERVED01());
        helper.setText(R.id.tvLotState,item.getRESERVED04());

        setEditListener(helper.getView(R.id.etNum),item);


    }

    public void setShiftNo(String shiftNo){
        this.mShiftNo = shiftNo;
    }

    private void setEditListener(EditText editText, ChangeShiftEntity.ChangeShift item) {
        if (editText.getTag() instanceof TextWatcher) {
            editText.removeTextChangedListener((TextWatcher) editText.getTag());
        }

        TextWatcher watcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setCOMMENTS(s.toString());
            }
        };

        editText.addTextChangedListener(watcher);
        editText.setTag(watcher);
    }
}
